/*
 * @Author: your name
 * @Date: 2020-08-26 11:51:19
 * @LastEditTime: 2020-08-27 14:45:56
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \examlist\src\store\Grade\index.js
 */
import { getList, deleteList, putList, postList } from '../../api/Grade'
import { Message } from 'view-design'
const state = {
  // 分配教室的班级
  AllList: []
}
const mutations = {
  setAllList(state, payload) {
    state.AllList = payload
    console.log(state.AllList)
  }
}
const actions = {
  // 获取数据
  async GetAllList({ commit }) {
    const { data: res } = await getList()
    // console.log(res)
    commit('setAllList', res.data)
  },
  // 添加班级
  async addList({ commit, dispatch }, data) {
    const { data: res } = await postList(data)
    console.log(res)
    if (res.code !== 1) {
      return Message.error(res.msg)
    }
    Message.success(res.msg)
  },
  // 编辑
  async editList({ commit, dispatch }, data) {
    const { data: res } = await putList(data)
    console.log(res)
    if (res.code !== 1) {
      return Message.error(res.msg)
    }
    Message.success(res.msg)
  },
  // 删除
  async deleteList({ commit, dispatch }, id) {
    const { data: res } = await deleteList(id)
    console.log(res)
    if (res.code !== 1) {
      return Message.error(res.msg)
    }
    Message.success(res.msg)
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
